﻿using MvcApplication.Common;
using MvcApplication.Entity;
using MvcApplication.Interface;
using System.Web.Mvc;

namespace MvcApplication.Controllers
{
    public class SinglePageController : Controller
    {
        IPostService _postService;

        public SinglePageController(IPostService postService)
        {
            _postService = postService;
        }

        //
        // GET: /SinglePage/
        [Permission(Entity.Menu.单页面管理, Entity.PermissionType.访问)]
        public ActionResult List(Pager pager, PostFilter filter)
        {
            filter.classify = PostClassify.单页页面;
            var postPage = _postService.GetPosts(pager, filter);
            return View(postPage);
        }

        [Permission(Entity.Menu.单页面管理, Entity.PermissionType.编辑)]
        public ActionResult Edit(long? id)
        {
            Post post = new Post();
            if (id.HasValue)
            {
                post = _postService.GetPostByID(id.Value);
                post.Categories.ForEach(t => t.Posts = null);
            }
            return View(post);
        }

    }
}
